<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增分类</title>
    <link rel="stylesheet" href="/static/css/oksub.css">
    <script type="text/javascript" src="/static/lib/loading/okLoading.js"></script>
    <script src="/static/lib/layui/layui.js"></script>
</head>
<body>
<form class="layui-form" action="" style="padding: 20px">
    {include file="common/select" field="$data"/}
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" required  lay-verify="required|name" placeholder="请输入名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">副名称</label>
        <div class="layui-input-block">
            <input type="text" name="vice_name" lay-verify="vice_name" placeholder="请输入副名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="text" name="sort" placeholder="排序"  lay-verify="sort" autocomplete="off" class="layui-input" value="0">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <textarea name="describe" placeholder="请输入描述" lay-verify="describe" class="layui-textarea"></textarea>
        </div>
    </div>
    {include file="common/upload_icon" field="$data"/}
    {include file="common/upload_category_image" field="$data"/}
    <div class="layui-form-item">
        <label class="layui-form-label">是否启用</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="0" title="否">
            <input type="radio" name="sex" value="1" title="是" checked>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">SEO标题</label>
        <div class="layui-input-block">
            <input type="text" name="seo_title" lay-verify="seo_title" placeholder="SEO标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">SEO关键词</label>
        <div class="layui-input-block">
            <input type="text" name="seo_keywords" lay-verify="seo_keywords"  placeholder="SEO关键词" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">SEO描述</label>
        <div class="layui-input-block">
            <textarea name="seo_desc" placeholder="请输入SEO描述"  lay-verify="seo_desc" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>

<script>
    layui.use(['form',"okLayer","okUtils"], function(){
        var form = layui.form;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;
        okLoading.close();
        form.verify({
            sort: function (value, item) {
                if (/^[0-9]+.?[0-9]*$/.test(value) !== true){
                    return '排序必须为数字！'
                }
                if ((value+'').length > 3 ){
                    return '排序位数最大3位数 999'
                }
            },
            name: function (value, item) {
                if ((value+'').length > 60 ){
                    return '最大字符数 60'
                }
            },
            vice_name: function (value, item) {
                if ((value+'').length > 80 ){
                    return '最大字符数 80'
                }
            },
            describe: function (value, item) {
                if ((value+'').length > 255){
                    return '最大字符数 255'
                }
            },
            seo_title: function (value, item) {
                if ((value+'').length > 100){
                    return '最大字符数 100'
                }
            },
            seo_keywords: function (value, item) {
                if ((value+'').length > 130){
                    return '最大字符数 130'
                }
            },
            seo_desc: function (value, item) {
                if ((value+'').length > 230){
                    return '最大字符数 230'
                }
            },
        })
        //监听提交
        form.on('submit(formDemo)', function(data){
            okUtils.ajax("{:addons_url('store://Category/add')}", "post", data.field, true).done(function (response) {
                if (response.status === 200) {
                    okLayer.greenTickMsg(response.msg, function () {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        parent.location.reload()
                    })
                }
            }).fail(function (error) {
                console.log(error)
            });
            return false;
        });
    });
</script>
</html>